home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.8 KB | 474 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSclBar.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWSCLNOT_H
- #include "FWSclNot.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWFONT_H
- #include "FWFont.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__CONTROLS__)
- #include <Controls.h>
- #endif
-
- #ifdef FW_BUILD_WIN
- #include <Windows.h>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- //========================================================================================
- // CLASS FW_CScrollBar
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CScrollBar)
- FW_DEFINE_CLASS_M1(FW_CScrollBar, FW_CNativeControl)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::FW_CScrollBar
- //----------------------------------------------------------------------------------------
-
- FW_CScrollBar::FW_CScrollBar(Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID) :
- FW_CNativeControl(ev, container, bounds, viewID),
- fMinorScrollUnits(FW_kFixedPos1),
- fMajorScrollUnits(FW_kFixedPos1),
- fScroller(NULL)
- {
- Initialize(ev, GetValue(ev), FW_CScrollBar::kDefaultScrollMin, FW_CScrollBar::kDefaultScrollMax);
-
- // Bind the scroll-bar to right or bottom egde of its superview by default
- FW_ViewBinding sbBindings = (bounds.Height() > bounds.Width()) ?
- FW_kFixedWidth + FW_kRightBinding + FW_kTopBinding + FW_kBottomBinding :
- FW_kFixedHeight + FW_kRightBinding + FW_kLeftBinding + FW_kBottomBinding;
- SetBindings(ev, sbBindings);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::FW_CScrollBar
- //----------------------------------------------------------------------------------------
-
- FW_CScrollBar::FW_CScrollBar(Environment* ev) :
- FW_CNativeControl(ev),
- fMinorScrollUnits(FW_kFixedPos1),
- fMajorScrollUnits(FW_kFixedPos1),
- fScroller(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::~FW_CScrollBar
- //----------------------------------------------------------------------------------------
-
- FW_CScrollBar::~FW_CScrollBar()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::Initialize(Environment *ev, FW_ControlValue value, FW_ControlValue min,
- FW_ControlValue max)
- {
- FW_CRect bounds = GetBounds(ev);
- FW_ViewBinding sbBindings = GetBindings(ev);
-
- // Ensure that width of vert. SB and height or horiz. SB are constant
- if (bounds.Height() > bounds.Width())
- {
- sbBindings |= FW_kFixedWidth;
- }
- else
- {
- sbBindings |= FW_kFixedHeight;
- }
- SetBindings(ev, sbBindings);
-
- // Create the control helper
- #ifdef FW_BUILD_MAC
- fControlHelper = new FW_CPrivMacScrollBarControlHelper(ev, this, value, min, max, scrollBarProc);
- #endif
-
- #ifdef FW_BUILD_WIN
- // TO UPDATE
- fControlHelper = new FW_CPrivWinControlHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinScrollBarHelper), this);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::PrivSetValue
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CScrollBar::PrivSetValue(Environment *ev, FW_ControlValue value, ODFacet* facet)
- {
- // Update the native control. Return false if value was not changed
- if (FW_CNativeControl::PrivSetValue(ev, value, facet))
- {
- // Send a control message to its receivers
- if (GetMessage(ev) != FW_kScrollMsg && GetMessage(ev) != FW_kNullMsg)
- Notify(ev, FW_CControlNotification(this));
-
- return true;
- }
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::ControlClicked
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::ControlClicked(Environment *ev, FW_ControlValue delta, ODFacet* facet)
- {
- // Update the control first
- if (PrivSetValue(ev, GetValue(ev) + delta, facet))
- {
- // Propagate the scrolling notification and ask to scroll
- FW_Fixed fxDelta = FW_IntToFixed(delta);
- ScrollPositionChanged(ev, fxDelta, true);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::Direction
- //----------------------------------------------------------------------------------------
- // Figure out which direction we're scrolling
-
- FW_XYSelector FW_CScrollBar::ScrollingDirection(Environment *ev) const
- {
- FW_CRect bounds = GetBounds(ev);
- return (bounds.Height() > bounds.Width()) ? FW_kVertical : FW_kHorizontal;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::ScrollPositionChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::ScrollPositionChanged(Environment *ev, FW_Fixed delta, FW_Boolean shouldScroll)
- {
- // ----- Notify receivers of the changes in scroll position
- FW_CScrollNotification notification(this, ScrollingDirection(ev), delta, shouldScroll);
- Notify(ev, notification);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetDefaultScrollBarSize
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CScrollBar::GetDefaultScrollBarSize()
- {
- #ifdef FW_BUILD_MAC
- return FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(15));
- #endif
- #ifdef FW_BUILD_WIN
- return FW_CPoint(FW_IntToFixed(::GetSystemMetrics(SM_CXHSCROLL)),
- FW_IntToFixed(::GetSystemMetrics(SM_CXVSCROLL)));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::DoActivateEvent
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::DoActivateEvent(Environment *ev, const FW_CActivateEvent& theActivateEvent)
- {
- if (IsVisible(ev) == false)
- return;
-
- #ifdef FW_BUILD_MAC
- ODFacet* facet = theActivateEvent.GetFacet(ev);
- FW_CViewContext vc(ev, this, facet);
-
- FW_CPlatformPoint qdPoint = vc.LogicalToDevice(FW_kZeroPoint);
- FW_CPlatformPoint qdSize = GetSize(ev).AsPlatformPoint();
-
- if (theActivateEvent.IsActivating(ev))
- {
- // Draw scrollbar immediately
- fControlHelper->Show(qdPoint, qdSize);
- }
- else
- {
- fControlHelper->Hide();
- Draw(ev, facet, NULL);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- // [TODO]
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetMinorScrollUnits
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetMinorScrollUnits(Environment *ev, FW_Fixed units)
- {
- FW_UNUSED(ev);
- fMinorScrollUnits = units;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetMajorScrollUnits
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetMajorScrollUnits(Environment *ev, FW_Fixed units)
- {
- FW_UNUSED(ev);
- fMajorScrollUnits = units;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollMax
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollMax(Environment *ev, FW_Fixed units)
- {
- FW_UNUSED(ev);
- #ifdef FW_BUILD_MAC
- fControlHelper->SetMax(FW_FixedToInt(units));
- #endif
-
- #ifdef FW_BUILD_WIN
- // [TODO]
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- fScrollBarHelper->SetScrollRange(min, FW_FixedToInt(units));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollMin
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollMin(Environment *ev, FW_Fixed units)
- {
- FW_UNUSED(ev);
- #ifdef FW_BUILD_MAC
- fControlHelper->SetMin(FW_FixedToInt(units));
- #endif
-
- #ifdef FW_BUILD_WIN
- // [TODO]
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- fScrollBarHelper->SetScrollRange(FW_FixedToInt(units), max);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollPos
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollPos(Environment *ev, FW_Fixed units)
- {
- SetValue(ev, FW_FixedToInt(units));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollPos
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollPos(Environment *ev, FW_Fixed range, FW_Fixed pos)
- {
- FW_Fixed units = FW_kFixed0;
- if (range != FW_kFixed0)
- units = FW_WideMultiply(GetScrollMax(ev) - GetScrollMin(ev), pos) / range + GetScrollMin(ev);
-
- SetValue(ev, FW_FixedToInt(units));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- FW_CNativeControl::Flatten(ev, stream);
-
- short min = fControlHelper->GetMin();
- short max = fControlHelper->GetMax();
-
- stream << min;
- stream << max;
- stream << fMinorScrollUnits;
- stream << fMajorScrollUnits;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CNativeControl::InitializeFromStream(ev, stream);
-
- short min, max;
- FW_Fixed major, minor;
-
- stream >> min >> max;
- stream >> minor >> major;
-
- SetMinorScrollUnits(ev, minor);
- SetMajorScrollUnits(ev, major);
-
- // [LSD] check for valid 16 bits value for scroll-bar
- FW_ControlValue value = GetValue(ev);
- FW_ASSERT(value <= FW_MAXINT16 && value >= FW_MININT16);
-
- Initialize(ev, value, min, max);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetMinorScrollUnits
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CScrollBar::GetMinorScrollUnits(Environment*) const
- {
- return fMinorScrollUnits;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetMajorScrollUnits
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CScrollBar::GetMajorScrollUnits(Environment*) const
- {
- return fMajorScrollUnits;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetScrollMax
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CScrollBar::GetScrollMax(Environment*) const
- {
- #ifdef FW_BUILD_MAC
- return FW_IntToFixed(fControlHelper->GetMax());
- #endif
-
- #ifdef FW_BUILD_WIN
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- return FW_IntToFixed(max);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetScrollMin
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CScrollBar::GetScrollMin(Environment*) const
- {
- #ifdef FW_BUILD_MAC
- return FW_IntToFixed(fControlHelper->GetMin());
- #endif
-
- #ifdef FW_BUILD_WIN
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- return FW_IntToFixed(min);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetScrollPos
- //----------------------------------------------------------------------------------------
-
- FW_Fixed FW_CScrollBar::GetScrollPos(Environment*) const
- {
- #ifdef FW_BUILD_MAC
- return FW_IntToFixed(fControlHelper->GetValue());
- #endif
-
- #ifdef FW_BUILD_WIN
- return FW_IntToFixed(fScrollBarHelper->GetScrollPos());
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::PrivAttachToScroller
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::PrivAttachToScroller(Environment*ev, FW_CPrivBaseScroller* scroller)
- {
- FW_UNUSED(ev);
- fScroller = scroller;
- }